package com.lx.javasunmmrize.prototype;

/**
 * @Description 克隆问题:如果要创建多个和该对象属性相同的对象
 *  实现接口，重写clone()方法，达到能通过拷贝属性创建新的对象的目的
 *
 *  浅拷贝：即使用默认的clone方法实现
 *
 * @Author lx
 * @Date 2021/2/26 23:30
 **/
public class Cat implements Cloneable{

    private String name;
    private String color ;

    public Cat getFriend() {
        return friend;
    }

    public void setFriend(Cat friend) {
        this.friend = friend;
    }

    private Cat friend;

    public Cat(String name, String color) {
        super();
        this.name = name;
        this.color = color;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    @Override
    public String toString() {
        return "Cat{" +
                "name='" + name + '\'' +
                ", color='" + color + '\'' +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Cat cat = null;
        try {
            cat = (Cat) super.clone();
        }catch (Exception e){
            e.printStackTrace();
        }
        return cat;
    }
}
